<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" type="text/css" href="/admin/layui/css/layui.css" media="all"/>
</head>
<body>

<div class="layui-form">
    <div class="layui-form-item">
        <!--<div class="layui-inline">-->
            <!--<label class="layui-form-label" style="color:orangered;font-weight: bold;">绑定分销员:</label>-->
            <!--<div class="layui-input-block">-->
                <!--<select name="vending-username" lay-search>-->
                    <!--<option value="0">张三</option>-->
                    <!--<option value="1">曹操</option>-->
                    <!--<option value="2">刘备</option>-->
                    <!--<option value="2">初期</option>-->
                    <!--<option value="2">楚歌</option>-->
                <!--</select>-->
            <!--</div>-->
        <!--</div>-->

        <div class="layui-inline">
            <label class="layui-form-label">手机</label>
            <div class="layui-input-block">
                <input type="text" name="phone" placeholder="请输入" autocomplete="off" class="layui-input" id="phone">
            </div>
        </div>

        <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-useradmin" id="searchMember">
                <i class="layui-icon layui-icon-search"></i>
            </button>
        </div>
    </div>
</div>
<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>

<script type="text/html" id="toolbarDemo">

    <!--<div class="layui-form layui-card-header layuiadmin-card-header-auto">-->
        <!--<div class="layui-form-item">-->
            <!--<div class="layui-inline">-->
                <!--<label class="layui-form-label">手机</label>-->
                <!--<div class="layui-input-block">-->
                    <!--<input type="text" name="phone" placeholder="请输入" autocomplete="off" class="layui-input">-->
                <!--</div>-->
            <!--</div>-->
            <!--<div class="layui-inline">-->
                <!--<button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="member-search">-->
                    <!--<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>-->
                <!--</button>-->
            <!--</div>-->
        <!--</div>-->
    <!--</div>-->

</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="binding">删除</a>
</script>


<script src="/admin/layui/layui.js" charset="utf-8"></script>
<script>
    layui.use(['table','jquery','element','form','layer'], function(){
        var table = layui.table
            , $ = layui.jquery
            , layer = layui.layer
            , form = layui.form
            , element = layui.element;

            table.render({
                elem: '#tableId'
                ,url:'/salesMan/getAllSalesMan'
                ,toolbar: '#toolbarDemo'
                ,cellMinWidth: 200 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                ,title: '用户数据表'
                ,limit:20
                ,totalRow:true
                ,cols: [        //  "[["需要将两个括号拆开换行，因为[[…]]之间的表达式在Thymeleaf被认为是内联表达式
                    [
                    {type: 'checkbox', fixed: 'left'}
                    ,{field:'mobile', title:'手机号', width:120, unresize: true, align:'center',sort: true}
                    ,{field:'nickname', title:'昵称', width:200, edit: 'text',align:'center'}
                    // ,{field:'order_num', title:'邮箱', width:150, edit: 'text', align:'center',templet: function(res){
                    //         return '<em>'+ res.email +'</em>'
                    //     }}
                    ,{field:'order_num', title:'累计成交笔数', width:230, edit: 'text', sort: true,align:'center'}
                    ,{field:'money', title:'累计成交金额', width:230, edit: 'text', sort: true,align:'center'}
                    ,{field:'created_at', title:'加入时间', width:200,align:'center'}
                ]]
                ,page: true,id:'salesManTable'
            });

        //监听搜索
        form.on('submit(member-search)', function(data){
            var field = data.field;
            var phone = JSON.stringify(data.field).phone;
            if(!phone){
                return;
            }
            //执行重载
            table.reload('tableId', {
                where: field
            });
        });

        $(document).on("click", "#searchMember", function () {
            var phone = $("#phone").val();
            table.reload('salesManTable', {
                where: {phone: phone}
            });
        })
        

        //头工具栏事件
        table.on('toolbar(tableFilter)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(tableFilter)', function(obj){
            var data = obj.data;
            console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                layer.prompt({
                    formType: 2
                    ,value: data.email
                }, function(value, index){
                    obj.update({
                        email: value
                    });
                    layer.close(index);
                });
            }else if(obj.event == 'binding'){
            }
        });
    });
</script>

</body>
</html>